package edu.kaist.cs408.pof.backend.service;

import edu.kaist.cs408.pof.backend.dao.DishDaoImpl;
import edu.kaist.cs408.pof.backend.dao.RestaurantDaoImpl;
import edu.kaist.cs408.pof.backend.dao.TalkDaoImpl;
import edu.kaist.cs408.pof.common.model.DishVo;
import edu.kaist.cs408.pof.common.model.RestaurantVo;
import edu.kaist.cs408.pof.common.model.TalkVo;
import edu.kaist.cs408.pof.common.service.RestaurantSvc;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;

import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: duyleekun
 * Date: 5/9/12
 * Time: 7:55 PM
 * To change this template use File | Settings | File Templates.
 */
@Configurable
public class RestaurantSvcImpl implements RestaurantSvc {

	@Autowired
	RestaurantDaoImpl restaurantDao;

	@Autowired
	DishDaoImpl dishDao;

	@Autowired
	TalkDaoImpl talkDao;

	@Override
	public List<RestaurantVo> get(@QueryParam("openStatus") Integer open) {
		if (open == null)
			return restaurantDao.getRestaurants();
		else if (open.equals(1))
			return restaurantDao.getRestaurants(true);
		else
			return restaurantDao.getRestaurants(false);
	}

	@Override
	public RestaurantVo addDish(DishVo newDish, @QueryParam("restaurant") ObjectId restaurant) {
		newDish = dishDao.createDish(newDish);
		return restaurantDao.addDish(restaurant, newDish.getMid());
	}

	@Override
	public RestaurantVo rate(@QueryParam("restaurant") ObjectId restaurant, int score) {
		return restaurantDao.rate(restaurant, score);
	}

	@Override
	public RestaurantVo postTalk(@PathParam("restaurant") ObjectId restaurant, @QueryParam("user") ObjectId user, TalkVo talk) {
		talk = talkDao.createTalk(talk);
		talkDao.setTalk(talk.getMid(), user, restaurant, null);
		return restaurantDao.get(restaurant);
	}
}
